<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/lib/layui-v2.5.5/css/layui.css">
    <script src="/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>

    <style>
        .layui-form-item .layui-input-inline {
            width: 200px;
        }
        #userForm table tr {
            width: 100%;
            margin: 0 auto;
            display: flex;
            flex-wrap: nowrap;
            justify-content: center;
        }

        #userForm table tr td{
            display: flex;
            flex-wrap: nowrap;
            margin: 10px;
        }

        #userForm table tr td .layui-input{
            width: 200px;
        }

        #userForm table tr td .layui-form-label{
            width: 150px;
        }
    </style>

</head>
<body>
新增商品
<form class="layui-form" id="userForm">
    <table>
        <div class="app">

            <tr>
                <td><label class="layui-form-label">商品编码:</label>

                    <input
                            required lay-verify="required" autocomplete="off" class="layui-input" type="text" name="reaalname"
                            id="goodsSN"
                            size="20"/></td>
            </tr>

            <tr>
                <td>
                    <label class="layui-form-label"> 商品名称:</label><input
                        required lay-verify="required" autocomplete="off" class="layui-input" type="text" name="reaalname"
                        id="goodsName"
                        size="20"/>
                </td>
            </tr>


            <tr>
                <td>
                    <label class="layui-form-label">商品规格:</label><input
                        required lay-verify="required" autocomplete="off" class="layui-input" type="text" name="reaalname"
                        id="goodsFormat"
                        size="20"/>
                </td>
            </tr>

            <tr>
                <td>
                    <label class="layui-form-label">市场价:</label><input
                        required lay-verify="required" autocomplete="off" class="layui-input" type="text" name="reaalname"
                        id="marketPrice"
                        size="20"/>
                </td>
            </tr>

            <tr>
                <td>
                    <label class="layui-form-label">优惠价格:</label><input
                        required lay-verify="required" autocomplete="off" class="layui-input" type="text" name="reaalname"
                        id="realPrice"
                        size="20"/>
                </td>
            </tr>

            <tr>
                <td>
                    <label class="layui-form-label"> 商品说明:</label><input
                        required lay-verify="required" autocomplete="off" class="layui-input" type="text" name="reaalname"
                        id="note"
                        size="20"/>
                </td>
            </tr>

            <tr>
                <td>
                    <label class="layui-form-label">商品状态:</label>
                    <div class="layui-input-inline">
                        <select id="state" lay-verify="required"  lay-filter="industry" >
                            <option value="0">请选择</option>
                            <option value="1">在售</option>
                            <option value="2">下架</option>
                        </select>
                    </div>
                </td>
            </tr>

            <tr>
                <td>

                    <label class="layui-form-label">库存:</label><input
                        required lay-verify="required" autocomplete="off" class="layui-input" type="text" name="reaalname"
                        id="num"
                        size="20"/>


                </td>
            </tr>

            <tr>
                <td>
                    <label class="layui-form-label">单位:</label><input
                        required lay-verify="required" autocomplete="off" class="layui-input" type="text" name="reaalname"
                        id="unit"
                        size="20"/>
                </td>
            </tr>

            <tr>
                <td>
                    <div class="layui-inline">
                        <label class="layui-form-label">创建时间:</label>
                            <div class="layui-input-inline">
                        <input type="date" class="layui-input" id="createTime" placeholder="yyyy-MM-dd HH:mm:ss">
                            </div>
                    </div>
                </td>
            </tr>


            <tr>
                <td>
                    <label class="layui-form-label"></label><input
                        required lay-verify="required" autocomplete="off" class="layui-input" type="button" name="reaalname"
                        id="commit" value="提交"
                        size="20"/>
                    <input
                            required lay-verify="required" autocomplete="off" class="layui-input" type="button" name="reaalname"
                            id="back" value="返回"
                            size="20"/>

                </td>
            </tr>

        </div>
    </table>
</form>
<script src="/lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
<script>
    layui.use('laydate', function() {
        var laydate = layui.laydate;

//常规用法
        laydate.render({
            elem: '#createtime'
            ,type: 'datetime'
        });
        laydate.render({
            elem: '#lastupdatetime'
            ,type: 'datetime'
        });
    })
    layui.use(['form', 'table', `upload`, 'layer', 'jquery', 'laydate'], function () {
        var form = layui.form;
        var table = layui.table;
        var $ = layui.jquery;
        var layer = layui.layer;
        var laydate = layui.laydate;

        $("#commit").on("click",function () {
            var unit=$("#unit").val();
            var createTime=$("#createTime").val();
            var goodsSN = $("#goodsSN").val();
            var goodsName = $("#goodsName").val();
            var goodsFormat = $("#goodsFormat").val();
            var marketPrice = $("#marketPrice").val();
            var realPrice = $("#realPrice").val();
            var note = $("#note").val();
            var num = $("#num").val();
            var state = $("#state").val();
            console.log(state);
            if (goodsSN==""||goodsSN==null){
                alert("请输入编号");
                return false;
            }
            if (goodsName==""||goodsName==null){
                alert("请输入名称");
                return false;
            }
            if (goodsFormat==""||goodsFormat==null){
                alert("请输入规格");
                return false;
            }
            if (marketPrice==""||marketPrice==null){
                alert("请输入市场价");
                return false;
            }
            if (realPrice==""||realPrice==null){
                alert("请输入优惠价");
                return false;
            }
            if (note==""||note==null){
                alert("请输入说明");
                return false;
            }
            if (num==""||num==null){
                alert("请输入库存");
                return false;
            }
            if (unit==""||unit==null){
                alert("输入单位名称")
                return false;
            }
            if (createTime==""||createTime==null){
                alert("输入创建时间")
                return false;
            }
            if (state==""||state==null){
                alert("输入是否上架")
                return false;
            }
            $.ajax({
                url:"/goods/addGoods.do",
                type:"post",
                dataType:"json",
                data:{
                    "goodsSN":goodsSN,
                    "goodsName":goodsName,
                    "goodsFormat":goodsFormat,
                    "marketPrice":marketPrice,
                    "realPrice":realPrice,
                    "note":note,
                    "state":state,
                    "num":num,
                    "unit":unit,
                    "createTime":createTime,
                },
                success:function (rec) {
                    if (rec.code==0){
                        alert("添加成功")
                    }else {
                        alert("添加失败")
                        return false;
                    }
                }
            })
        })
   })

    $("#back").on("click",function () {
        location.href="/html/shopping/goodsAdd.html"

    })


</script>

</body>
</html>